import { Injectable } from '@angular/core';

import { Observable, of } from 'rxjs';
// 导入应Hero数据类型
import { Hero } from './hero';
// 导入数据
import { HEROES } from './mock-heroes';
// 注入MessageService到折柳的HeroService
import { MessageService } from './message.service';

@Injectable({
  providedIn: 'root',
})
export class HeroService {

  constructor(private messageService: MessageService) { }

  getHeroes(): Observable<Hero[]> {
    // of(HEROES)会返回一个Observable<Hero[]>，它会发出单个值，这个值就是这些模拟英雄的数组
    
    const heroes = of(HEROES);
    this.messageService.add('HeroService: fetched heroes');
    return heroes;
  }
}